package com.example.xiaodu.yuejian12.Activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.xiaodu.yuejian12.Bean.RegisterBean;
import com.example.xiaodu.yuejian12.Listener.RetrofitListener;
import com.example.xiaodu.yuejian12.Model.UserModel;
import com.example.xiaodu.yuejian12.R;

public class Register extends Activity {

    private EditText username,password,phone;
    private Button confirm,back;
    private Intent intent,intent2;
    private RetrofitListener<RegisterBean> listener;
    private UserModel userModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

       username=findViewById(R.id.edit_username);
        password=findViewById(R.id.edit_password);
        phone=findViewById(R.id.edit_phone);
        confirm=findViewById(R.id.btn_confirm);
        back=findViewById(R.id.btn_back);

        listener=new RetrofitListener<RegisterBean>() {
            @Override
            public void onSuccess(RegisterBean registerBean) {
                if ("1".equals(registerBean.getFlag())) {
                    Toast.makeText(Register.this, "注册成功", Toast.LENGTH_LONG).show();
                    intent2 = new Intent(Register.this, Login.class);
                    startActivity(intent2);
                }
            }

            @Override
            public void onFail(String msg) {
                Toast.makeText(Register.this, msg, Toast.LENGTH_LONG).show();
            }
        };

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                intent=new Intent(Register.this,Login.class);
                startActivity(intent);
            }
        });

        confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                userModel=new UserModel();
                userModel.userRegister(username.getText().toString(),password.getText().toString(),phone.getText().toString(),listener);

            }
        });



    }
}
